﻿using System;
using UnityEngine;

public class ClampCamera : MonoBehaviour
{
    public Camera cam;
    public Rect clampingRect;

    private void LateUpdate()
    {
        if (this.cam != null)
        {
            Rect worldRect = this.cam.GetWorldRect(base.transform);
            if (this.clampingRect.size != Vector2.zero)
            {
                Rect rect2 = worldRect.ClampPosition(this.clampingRect);
                if (this.clampingRect.width == 0f)
                {
                    rect2.x = worldRect.x;
                }
                if (this.clampingRect.height == 0f)
                {
                    rect2.y = worldRect.y;
                }
                worldRect = rect2;
            }
            this.cam.SetWorldRect(worldRect, base.transform);
        }
    }

    private void OnDrawGizmos()
    {
        DebugDraw.DrawRect(this.clampingRect, Color.red, 0.01f);
    }
}

